from torchvision.utils import make_grid
from matplotlib import pyplot as plt
import numpy as np


def tensor_visual(tensor, nrow):
    """
    将tensro拼凑成一张CHW图，normalize指定归一化到[0,1]
    :param tensor: BS,C,H,W
    :param nrow:
    :return:
    """
    vis = make_grid(tensor, nrow=nrow, normalize=True, padding=10, pad_value=1)
    npimg = vis.numpy()
    plt.figure()
    plt.imshow(np.transpose(npimg, (1, 2, 0)), interpolation='nearest')
    plt.show()
